//package com.example.saiweisi.common;
//
//import com.example.saiweisi.mapper.userMapper.ClothesMapper;
//import com.example.saiweisi.mapper.userMapper.OrderMapper;
//import com.example.saiweisi.mapper.userMapper.UserMapper;
//import com.example.saiweisi.model.Order;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.mail.SimpleMailMessage;
//import org.springframework.mail.javamail.JavaMailSender;
//import org.springframework.stereotype.Component;
//
//import javax.annotation.PostConstruct;
//import javax.annotation.Resource;
//import java.util.List;
//import java.util.Timer;
//import java.util.TimerTask;
//@Component
//public class SystemTimer {
//    @Resource
//    OrderMapper orderMapper;
//    @Resource
//    ClothesMapper clothesMapper;
//    @Resource
//    UserMapper userMapper;
//    @Value("${spring.mail.username}")
//    private String from;
//    @Resource
//    private JavaMailSender javaMailSender;
//    @PostConstruct
//    public void main() {
//        TimerTask sendEmailTask = new TimerTask() {
//            @Override
//            public void run() {
//                List<Order> orderList = orderMapper.getAll();
//                for (int i = 0; i < orderList.size(); i++) {
//                    if(orderMapper.getfinish(orderList.get(i).getOrderId())==0){
//                        int isSend = orderMapper.getIsSendByOrderId(orderList.get(i).getOrderId());
//                        if (isSend == 0){
//                            int userId= userMapper.getUserIdByOrderId(orderList.get(i).getOrderId());
//                            String email = userMapper.getEmailByUserId(userId);
//                            if(email!=""&&email!=null){
//                                SimpleMailMessage message = new SimpleMailMessage();
//                                message.setFrom(from);
//                                message.setSubject("洗衣完成");
//                                message.setText("您在塞维斯洗衣馆的第" + orderList.get(i).getOrderId() + "号订单已经完成，请及时取衣");
//                                message.setTo(email);
//                                javaMailSender.send(message);
//                                orderMapper.setIsSend(orderList.get(i).getOrderId());
//                            }
//                        }
//                    }
//
//                }
//            }
//        };
//
//        Timer timer = new Timer();
//        // 设定任务开始的时间为系统启动后1秒
//        long delay =  1000;
//        // 设定任务执行的周期为1小时
//        long period = 60 * 60 * 1000;
//        // 启动计时器
//        timer.schedule(sendEmailTask, delay, period);
//    }
//}